package com.xiao.hao.service;


import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import com.xiao.hao.utils.PageResult;
import javax.annotation.Resource;
import com.xiao.hao.utils.Result;
import com.xiao.hao.req.XhThoughtProcessInsertReq;
import com.xiao.hao.req.XhThoughtProcessQueryPageReq;
import com.xiao.hao.req.XhThoughtProcessUpdateReq;
import com.xiao.hao.convertor.XhThoughtProcessConvertor;
import com.xiao.hao.entity.XhThoughtProcess;
import com.xiao.hao.facade.XhThoughtProcessFacade;
import com.xiao.hao.utils.BaseId;
import com.xiao.hao.mapper.XhThoughtProcessMapper;



/**
*
*
* @Description 内容过程表 服务实现层
* @Author xiaohao
* @Date 2025-03-01 16:18:19
*/
@Service
@Slf4j
public class XhThoughtProcessServiceImpl implements XhThoughtProcessFacade {

    @Resource
    XhThoughtProcessMapper mapper;


    /**
    * 功能描述: 角色新增
    *
    * @param req
    * @return com.xiao.hao.utils.Result
    * @author xiaohao
    * @date 2025-03-01 16:18:19
    */
    @Override
    public Result insert(XhThoughtProcessInsertReq req) {
        return Result.succeed(mapper.insert(XhThoughtProcessConvertor.INSTANCE.reqToEntity(req)));
    }


    /**
    * 功能描述: 角色修改
    *
    * @param req
    * @return com.xiao.hao.utils.Result
    * @author xiaohao
    * @date 2025-03-01 16:18:19
    */
    @Override
    public Result update(XhThoughtProcessUpdateReq req) {
        return Result.succeed(mapper.updateById(XhThoughtProcessConvertor.INSTANCE.reqToEntity(req)));
    }


    /**
    * 功能描述: 删除角色
    *
    * @param req
    * @return com.xiao.hao.utils.Result
    * @author xiaohao
    * @date 2025-03-01 16:18:19
    */
    @Override
    public Result delete(BaseId req) {
        return Result.succeed(mapper.deleteById(req.getId()));
    }

    /**
    * 功能描述: 角色分页查询
    *
    * @param req
    * @return com.xiao.hao.utils.PageResult
    * @author xiaohao
    * @date 2025-03-01 16:18:19
    */
    @Override
    public PageResult queryPage(XhThoughtProcessQueryPageReq req) {
        Page<XhThoughtProcess> page = mapper.selectPage(new Page(req.getNum(), req.getSize()), new LambdaQueryWrapper<XhThoughtProcess>().orderByDesc(XhThoughtProcess::getCreateTime));
        return PageResult.result(page.getTotal(), XhThoughtProcessConvertor.INSTANCE.entityListToRespList(page.getRecords()));
    }

}



